﻿using PMS.Core.ComponentModel;
using PMS.Core.Infrastructure;
using System.Collections.Generic;
using System.ComponentModel;

namespace PMS.Web.Framework.StartupCfgs.StartupTasks
{
    /// <summary>
    /// Startup task for the registration custom type converters
    /// </summary>
    public class TypeConverterRegistrationStartUpTask : IStartupTask
    {
        /// <summary>
        /// Executes a task
        /// 增加数据类型转换Converter支持，主要用于setting表中各种数据类型转换
        /// Dictionary<int,int> 转换时多个item之间";"分隔，每对KeyValuePair","分隔
        /// </summary>
        public void Execute()
        {
            //lists
            TypeDescriptor.AddAttributes(typeof(List<int>), new TypeConverterAttribute(typeof(GenericListTypeConverter<int>)));
            TypeDescriptor.AddAttributes(typeof(List<decimal>), new TypeConverterAttribute(typeof(GenericListTypeConverter<decimal>)));
            TypeDescriptor.AddAttributes(typeof(List<string>), new TypeConverterAttribute(typeof(GenericListTypeConverter<string>)));

            //dictionaries
            TypeDescriptor.AddAttributes(typeof(Dictionary<int, int>), new TypeConverterAttribute(typeof(GenericDictionaryTypeConverter<int, int>)));

        }

        /// <summary>
        /// Gets order of this startup task implementation
        /// </summary>
        public int Order => StartupTaskOrderConfig.TypeConverterOrder;
    }

}
